<?php

### Error handling

function PHPGWTErrorHandler($errno, $errstr, $errfile, $errline){
 die("Error #".$errno." in ".$errfile." at line ".$errline.": ".$errstr);
}

set_error_handler("PHPGWTErrorHandler");

function checkLastJsonError(){
 $error = json_last_error();
	
 switch($error){
  case JSON_ERROR_DEPTH:
   die('JSON Error: The maximum stack depth has been exceeded');
  case JSON_ERROR_STATE_MISMATCH:
   die('JSON Error: Invalid or malformed JSON');
  case JSON_ERROR_CTRL_CHAR:
   die('JSON Error: Control character error, possibly incorrectly encoded');
  case JSON_ERROR_SYNTAX:
   die('JSON Error: Syntax error');
  case JSON_ERROR_UTF8: 
   die('JSON Error: Malformed UTF-8 characters, possibly incorrectly encoded');
 }
}

### Processing request
$data = json_decode($_POST['data']);
checkLastJsonError();

$service = $data->service;
$function = $data->function;
$parameters = (array) $data->parameters;

$services = array();
$files = array();
$ret = NULL;
